function fmtDate(obj,isType){    
    var date = new Date(obj);  
    var y = date.getFullYear();    
    var m = date.getMonth() + 1;    
    m = m < 10 ? ('0' + m) : m;    
    var d = date.getDate();    
    d = d < 10 ? ('0' + d) : d;    
    var h = date.getHours();  
    h = h < 10 ? ('0' + h) : h;  
    var minute = date.getMinutes();  
    var second = date.getSeconds();  
    minute = minute < 10 ? ('0' + minute) : minute;    
    second = second < 10 ? ('0' + second) : second;  
    var l = ["日","一","二","三","四","五","六"];
    var d_index =date.getDay();
    var week = "星期" + l[d_index]; 
   if(isType){
    return {
        "ymd":y + '-' + m + '-' + d,
        "ymdhis":y + '-' + m + '-' + d+' '+h+':'+minute+':'+second,
         "md":m + '-' + d, 
         "ym":m + '/' + y,
         "week":week,
         "d":d,
         "hd":h+':'+minute+':'+second
     }
   }else{
       return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second
   }
    
}
function getDateDiff(startDate,endDate)  
{  
    var startTime = new Date(startDate).getTime();     
    var endTime = new Date(endDate).getTime();     
    var dates = Math.abs((startTime - endTime))/(1000*60*60*24);     
    return  dates;    
}
function addDate(date,days){ 
    var d=new Date(date); 
    d.setDate(d.getDate()+days); 
    var m=d.getMonth()+1; 
    let {ymd,md}=fmtDate(d,true);
    return {yearDay:ymd
        ,monthDay:md}
  } 

  function minusDate(startTime){
    var d = new Date(startTime);//获取当前时间
    d.setDate(d.getDate()-1);//设置天数 -1 天
    var m=d.getMonth()+1
    // var time = fmtDate("yyyy-MM-dd");
    let {ymd,md}=fmtDate(d,true);
    return {yearDay:ymd
        ,monthDay:md}
  }  
export{
    fmtDate,
    getDateDiff,
    addDate,
    minusDate
    
}